package com.example.springbean.pkg;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author 15871
 */
@Component
public class AllBeanPostProcessor implements BeanPostProcessor {


    /**
     * 每个bean初始化前的修改操作
     *
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("beanTest")) {
            System.out.println("初始化之前bean" + bean);
        }

        return bean;
    }

    /**
     * 每个bean初始化操作后
     *
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("beanTest")) {
            System.out.println("bean初始化之后的操作");
        }
        return bean;
    }
}
